<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>module Roled::ActsAs - Roled</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="module">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/roled/acts_as.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    
    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-add_permission">#add_permission</a>
    
    <li><a href="#method-i-create_aro">#create_aro</a>
    
    <li><a href="#method-i-current_aro">#current_aro</a>
    
    <li><a href="#method-i-has_no_permission_to">#has_no_permission_to</a>
    
    <li><a href="#method-i-has_permission_to">#has_permission_to</a>
    
    <li><a href="#method-i-has_permission_to-3F">#has_permission_to?</a>
    
    <li><a href="#method-i-model_name">#model_name</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../README_rdoc.html">README</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../Roled.html">Roled</a>
  
    <li><a href="../Roled/Aco.html">Roled::Aco</a>
  
    <li><a href="../Roled/AcosAro.html">Roled::AcosAro</a>
  
    <li><a href="../Roled/ActsAs.html">Roled::ActsAs</a>
  
    <li><a href="../Roled/ActsAs/ClassMethods.html">Roled::ActsAs::ClassMethods</a>
  
    <li><a href="../Roled/Aro.html">Roled::Aro</a>
  
    <li><a href="../Roled/Core.html">Roled::Core</a>
  
    <li><a href="../Roled/Generators.html">Roled::Generators</a>
  
    <li><a href="../Roled/Generators/InstallGenerator.html">Roled::Generators::InstallGenerator</a>
  
    <li><a href="../Roled/RakeTasks.html">Roled::RakeTasks</a>
  
    <li><a href="../Roled/RakeTasks/RakeTasks.html">Roled::RakeTasks::RakeTasks</a>
  
    <li><a href="../InstallRoled.html">InstallRoled</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="module">module Roled::ActsAs</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-create_aro" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create_aro</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="create_aro-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_aro</span>
  <span class="ruby-constant">Aro</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foreign_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:model</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">model_name</span>).<span class="ruby-identifier">save</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- create_aro-source -->
          
        </div>

        

        
      </div><!-- create_aro-method -->

    
      <div id="method-i-current_aro" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">current_aro</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="current_aro-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 13</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">current_aro</span>
  <span class="ruby-constant">Aro</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:model</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">model_name</span>, <span class="ruby-value">:foreign_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- current_aro-source -->
          
        </div>

        

        
      </div><!-- current_aro-method -->

    
      <div id="method-i-has_no_permission_to" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">has_no_permission_to</span><span
            class="method-args">(controller = nil, action = nil)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="has_no_permission_to-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 65</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">has_no_permission_to</span>(<span class="ruby-identifier">controller</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">action</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">add_permission</span>(<span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- has_no_permission_to-source -->
          
        </div>

        

        
      </div><!-- has_no_permission_to-method -->

    
      <div id="method-i-has_permission_to" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">has_permission_to</span><span
            class="method-args">(controller = '', action = '')</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="has_permission_to-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">has_permission_to</span>(<span class="ruby-identifier">controller</span> = <span class="ruby-string">''</span>, <span class="ruby-identifier">action</span> = <span class="ruby-string">''</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">add_permission</span>(<span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- has_permission_to-source -->
          
        </div>

        

        
      </div><!-- has_permission_to-method -->

    
      <div id="method-i-has_permission_to-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">has_permission_to?</span><span
            class="method-args">(controller, action)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="has_permission_to-3F-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 21</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">has_permission_to?</span>(<span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">controller</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">action</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
  
  <span class="ruby-identifier">options</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">global_options</span>
  <span class="ruby-identifier">groups</span> = []
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">blank?</span> 
    <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>,<span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-value">:belongs_to</span>
        <span class="ruby-keyword">if</span>(<span class="ruby-keyword">defined?</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>)))
          <span class="ruby-identifier">groups</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>)
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">parent</span> = <span class="ruby-node">&quot;#{controller}_controller&quot;</span>
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:parent</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parent</span>, <span class="ruby-value">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">action</span>).<span class="ruby-identifier">exists?</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
  
  <span class="ruby-identifier">ids</span> = <span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;parent IN (?) AND action is NULL OR parent = ? AND action = ?&quot;</span>, [<span class="ruby-identifier">parent</span>,<span class="ruby-string">&quot;all&quot;</span>], <span class="ruby-identifier">parent</span>, <span class="ruby-identifier">action</span>).<span class="ruby-identifier">order</span>(<span class="ruby-string">'action desc'</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AcosAro</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">'aco_id IN (?) AND aro_id = ?'</span>, <span class="ruby-identifier">ids</span>, <span class="ruby-identifier">current_aro</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">exists?</span>
    <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">groups</span>.<span class="ruby-identifier">blank?</span>
      <span class="ruby-identifier">groups</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">group</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">result</span> = <span class="ruby-identifier">group</span>.<span class="ruby-identifier">has_permission_to?</span>(<span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span>)
        <span class="ruby-keyword">if</span>(<span class="ruby-operator">!</span><span class="ruby-identifier">result</span>.<span class="ruby-identifier">nil?</span>)
          <span class="ruby-keyword">return</span> <span class="ruby-identifier">result</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">AcosAro</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">'aco_id IN (?) AND aro_id = ?'</span>, <span class="ruby-identifier">ids</span>, <span class="ruby-identifier">current_aro</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">order</span>(<span class="ruby-string">'aco_id desc'</span>).<span class="ruby-identifier">first</span>.<span class="ruby-identifier">allowed</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- has_permission_to-3F-source -->
          
        </div>

        

        
      </div><!-- has_permission_to-3F-method -->

    
      <div id="method-i-model_name" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">model_name</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="model_name-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 9</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">model_name</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-string">&quot;Controller&quot;</span>, <span class="ruby-string">&quot;&quot;</span>).<span class="ruby-identifier">singularize</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- model_name-source -->
          
        </div>

        

        
      </div><!-- model_name-method -->

    
    </section><!-- public-instance-method-details -->
  
     <section id="protected-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Protected Instance Methods</h3>

    
      <div id="method-i-add_permission" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add_permission</span><span
            class="method-args">(controller = nil, action = nil, allowed = nil)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="add_permission-source">
            <pre><span class="ruby-comment"># File lib/roled/acts_as.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_permission</span>(<span class="ruby-identifier">controller</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">action</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">allowed</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">controller</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
  
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">controller</span> <span class="ruby-operator">!=</span> <span class="ruby-value">:all</span>
    <span class="ruby-identifier">controller</span> = <span class="ruby-node">&quot;#{controller}_controller&quot;</span>
  <span class="ruby-keyword">end</span>
  
  <span class="ruby-keyword">if</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">blank?</span>)
    <span class="ruby-keyword">if</span>(<span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;parent = ? AND action is NULL&quot;</span>, <span class="ruby-identifier">controller</span>).<span class="ruby-identifier">exists?</span>)
      <span class="ruby-identifier">aco</span> = <span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;parent = ? AND action is NULL&quot;</span>, <span class="ruby-identifier">controller</span>).<span class="ruby-identifier">first</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span>(<span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:parent</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>, <span class="ruby-value">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">action</span>).<span class="ruby-identifier">exists?</span>)
      <span class="ruby-identifier">aco</span> = <span class="ruby-constant">Aco</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:parent</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>, <span class="ruby-value">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">action</span>).<span class="ruby-identifier">first</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">aro</span> = <span class="ruby-identifier">current_aro</span>
  
  <span class="ruby-keyword">if</span>(<span class="ruby-identifier">aro</span>.<span class="ruby-identifier">blank?</span>)
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
  
  <span class="ruby-identifier">bind</span> = <span class="ruby-constant">AcosAro</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:aco_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">aco</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:aro_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_aro</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:allowed</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">allowed</span>)
  
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">valid?</span>
   <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">save</span>
   <span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-constant">AcosAro</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:aco_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">aco</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:aro_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_aro</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">exists?</span>
   <span class="ruby-constant">AcosAro</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:aco_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">aco</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:aro_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_aro</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">first</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-value">:allowed</span>, <span class="ruby-identifier">allowed</span>)
   <span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
   <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- add_permission-source -->
          
        </div>

        

        
      </div><!-- add_permission-method -->

    
    </section><!-- protected-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

